//
//  build.cpp
//  
//
//  Created by Nikita Luzyanin on 30.11.13.
//
//

#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

int main(int argc, char* argv[])
{
    int numberOfDisks = atoi(argv[1]);
    if ((numberOfDisks < 3)||(numberOfDisks > 5)) {
        cout << "Too much disks\n";
        return 1;
    }
    int numberOfBlocks = atoi(argv[2]);
    if ((numberOfBlocks < 100)||(numberOfBlocks > 10000)) {
        cout << "Too much blocks\n";
        return 1;
    }
    int sizeOfBlock = atoi(argv[3]);
    if ((sizeOfBlock < 256)||(sizeOfBlock > 2048)) {
        cout << "Size is too big\n";
        return 1;
    }
    
    char raidType[2];
    strcpy(raidType, argv[4]);
    if (strcmp(raidType, "0") != 0) {
        if (strcmp(raidType, "1") != 0) {
            if (strcmp(raidType, "3") != 0) {
                if (strcmp(raidType, "4") != 0) {
                    if (strcmp(raidType, "5") != 0) {
                        if (strcmp(raidType, "01") != 0) {
                            if (strcmp(raidType, "10") != 0) {
                                cout << "This level does not exist\n";
                                return 1;
                            }
                        }
                    }
                }
            }
        }
    }
    
    if (((strcmp(raidType, "01") == 0)||(strcmp(raidType, "10") == 0))&&(numberOfDisks != 4)) {
        cout << "Must be 4 disks for this RAID type\n";
        return 1;
    }
    
    ofstream NB;
    int sizeOfDisk = numberOfBlocks * sizeOfBlock + 1;
    for (int i = 0; i < numberOfDisks; i++) {
        char diskName[10];
        char diskNumber[10];
        sprintf(diskNumber, "%i", i);
        strcpy(diskName, "disk");
        strcat(diskName, diskNumber);
        NB.open(diskName);
        NB << numberOfDisks;
        NB << "\n";
        NB << numberOfBlocks;
        NB << "\n";
        NB << sizeOfBlock;
        NB << "\n";
        NB << raidType;
        NB << "\n";
        for (int j = 0; j < sizeOfDisk; j++) {
            NB << 0;
        }
        NB.close();
    }

    return 0;
}